<?php
class ImagesController extends AppController{
	var $name = 'Images';
	var $uses = array('Image','Categorie');
	var $helpers = array('Html','Session');
	var $components = array('Session');
	function findimagebyname(){
		$categories=$this->Categorie->find('all');
		//pr($categories);
		$this->set('categories',$categories);
		if(!empty($this->data)&&$this->data['Image']['imagename']!=null){
        //neu co thi truy van du lieu dua vao bien $users
        


        //pr($this->data['Image']);

        if(empty($this->data['Image']['select'])){
        $results=$this->Image->find('all',array('conditions'=>array('name LIKE '=>'%'.$this->data['Image']['imagename'].'%')));
        //goi du lieu tu controller len view
        //pr($this->Image->find('all',array('conditions'=>array('name LIKE '=>'%'.$this->data['Image']['imagename'].'%'))));

        $this->set('results',$results);
        }else{
        $results=$this->Image->find('all',array('conditions'=>array('name LIKE '=>'%'.$this->data['Image']['imagename'].'%','Categorie.id'=>$this->data['Image']['select']+1)));
        //goi du lieu tu controller len view
        //pr($this->Image->find('all',array('conditions'=>array('name LIKE '=>'%'.$this->data['Image']['imagename'].'%'))));

        $this->set('results',$results);

        }
        //$this->redirect(array('action'=>'searchresult'));

		}
	}	

	function findimagebycategories($categoryname){

		//$categories=$this->Categorie->find('all');
		//pr($categories);
		//$this->set('categories',$categories);



		//if(!empty($this->data)&&$this->data['Image']['select']!=null){
        //neu co thi truy van du lieu dua vao bien $users
        


        //pr($this->data['Image']);

        $results=$this->Image->find('all',array('conditions'=>array('Categorie.categoriename'=>$categoryname)));
        //goi du lieu tu controller len view
        //pr($this->Image->find('all',array('conditions'=>array('categorie_id LIKE '=>'%'.($this->data['Image']['select']+1).'%'))));

        $this->set('results',$results);
        //$this->redirect(array('action'=>'searchresult'));

		
		
	}
        function listcategories(){
                $categories=$this->Categorie->find('all');
                //pr($categories);
                //$this->set('categories',$categories);
                return $categories;
        }
}
?>